package rpcx_media_router_centre

import (
	"gobase/rpcx_work_flow/rpcx_connect_centre"
	"time"
)

type Method int64

const (
	Method_ADD Method = iota
	Method_GET
	Method_UPDATE
	Method_LIST
	Method_DELETE
)

const (
	//Stream_Status_Start
	Stream_Starting = iota
	//Stream_Status_Start_OK
	Stream_Pushing
	//Stream_Status_NoReader
	Stream_NoReaderTimer
	//Stream_Status_NoReaderTimeout
	//Stream_Status_Close
	Stream_Closing
	//Stream_Status_Closed
	//Stream_Status_Recycle
	Stream_Recycling
	//Stream_Status_Clear
)

type PingPong struct {
	Msg string
}

type Page struct {
	PagePre  int64
	PageNext int64
	ParamID  string
}

type ReqMedia struct {
	Page
	Media
}

type RespMedia struct {
	Response
	MediaList []*Media
}

type ReqMediaStream struct {
	Page
	Stream
}

type RespMediaStream struct {
	Response
	MediaStreamList []*Stream
}

// MergeStreamRect 合流参数
type MergeStreamRect struct {
	Screen     int64
	X          int64
	Y          int64
	Width      int64
	Height     int64
	DeviceID   string
	DeviceName string
	ChannelID  int64
	App        string
	MediaIP    string
	HttpPort   int64
	SSRCStr    string
	PlayUrl    string
}

// MergeStreamReq 视频合流请求
type MergeStreamReq struct {
	Tid           string
	Width         int64
	Height        int64
	ChildRect     []*MergeStreamRect
	GpuCardIndex  int64
	MergeMediaIP  string
	MergeHttpPort int64
	MergeApp      string
	MergeStreamID string
	MergeSSRCStr  string
	IsTest        bool   //获取测试合流
	ClientIp      string //客户端请求IP
	ClientArea    string //客户端请求所在地区编码
	TraceID       string
}

// ControlMergeStreamRequest 控制(获取、停止)合流请求
type ControlMergeStreamRequest struct {
	StreamID string
	Ssrc     string
	Tid      string
	App      string
}

// ControlMergeStreamResponse 控制(获取、停止)合流响应
type ControlMergeStreamResponse struct {
	Code         int64
	Msg          string
	Ssrc         string
	CmdStatusTip string
}

// MobilePhone 移动设备
type MobilePhone struct {
	DeviceSerial  string //设备序列号
	DeviceID      string //设备ID
	SteamID       string //视频流ID
	MediaID       string //媒体中心ID
	Cellphone     string //移动设备,手机号码
	Application   string //客户端应用
	MobChannelNum int64  //可用摄像头数量
	MobIMEI       string //设备IMEI(设备上网许可证)
	MobMAC        string //设备MAC
	MobIP         string //移动网络分配的ip地址
	MobPort       int64  //应用软件端口号
	MobAppURL     string //访问客户端的地址
	DeviceName    string //设备名称
}

// MobileDeviceResp 移动设备响应
type MobileDeviceResp struct {
	StreamID    string
	SSRCStr     string
	DeviceID    string
	ChannelID   int64
	PushIP      string
	PushPort    int64
	AppID       string
	RtmpPushURL string
	Msg         string
	Code        int64
	DeviceName  string
}

// MobileRespList mobile list resp
type MobileRespList struct {
	Response
	MobileDeviceRespList []*MobileDeviceResp
}

// UAVRequest 无人机请求参数
type UAVRequest struct {
	DeviceID string
	MediaID  string
}

type UAVInfo struct {
	ID         uint
	DeviceID   string
	MediaID    string
	IP         string //媒体中心IP
	RtmpPort   int64
	RtmpUrl    string
	NatRtmpUrl string
}

// UAVResponse 无人机返回值
type UAVResponse struct {
	Code int
	Msg  string
	Data UAVInfo
}

// MergeStreamResponse 视频合流响应
type MergeStreamResponse struct {
	ResponseList             []Response
	StartMergeStreamResponse MergeStreamReq
	Response
}

// PushStreamPort 推流端口
type PushStreamPort struct {
	RtpPort  int64
	RtcpPort int64
}

// StreamStatResponse 流状态响应
type StreamStatResponse struct {
	Code             int64
	Msg              string
	ReaderCount      int64
	TotalReaderCount int64
	Stream           string
	OriginUrl        string
	App              string
	Schema           string
	AliveSecond      int64
}

// PlayRequest 调阅请求
type PlayRequest struct {
	TID            string // 事务ID
	DeviceID       string
	StreamID       string
	SolutionID     string //接入方案ID /接入方案 名称
	UserCity       string
	AppID          string
	ClientID       string
	StartTime      int64
	EndTime        int64
	CloseTime      time.Time // 结构化中心关流时间
	ChannelID      int64
	DraggingRatio  float64
	OffsetTime     int64
	ScaleType      string
	DeviceCity     string
	IsSipSimulator bool                                //是否为国标模拟调阅
	IsStructure    bool                                //是否使用结构化中心
	IsMergeStream  bool                                //是否为合流的调阅请求
	IsUAV          bool                                //是否是无人机请求
	MediaCentre    rpcx_connect_centre.MediaCentreInfo //推流媒体中心信息
	DownloadSpeed  int64                               //下载速度
	Mp3FileName    string                              // 结构化中心拉流指定mp3文件名称则录制mp3文件，否则不录制
	Mp4FileName    string                              // 结构化中心拉流指定mp4文件名称则录制mp4文件，否则不录制
	TicketID       string                              // 工单ID(阳光业扩)
	PullStreamUrl  string                              // 工单业务拉流Url
	ClientIp       string                              //客户端请求IP
	ClientArea     string                              //客户端用户所在地区, 11位, 1-4位: 省市; 11位: 网络区域 1、内网 2、互联网大区 3、公共互联网; 例: 37010000001
	DeviceArea     string                              //设备所在地区, 11位, 1-4位: 省市; 11位: 网络区域 1、内网 2、互联网大区 3、公共互联网; 例: 37010000001
	EnableTcp      bool                                // true tcp推流 false udp推流
	IsNat          bool                                //是否是外网
	DccID          string                              //接入中心id
	TraceID        string                              //日志追踪id
}

// 视频调阅请求(带分辨率)
type PlayResolutionRatio struct {
	DeviceID  string
	StreamID  string
	TraceID   string //日志追踪id
	Width     int64
	Height    int64
	CloseTime time.Time //结构化中心关流时间
}

type HttpResponse struct {
	Code int64
	Msg  string
}

// Response 通用响应
type Response struct {
	ConnID  string
	ParamID string
	Method  int64
	IsOK    bool
	ErrCode int64
	ErrMsg  string
}

// PlayResponse 调阅响应
type PlayResponse struct {
	StreamID         string
	ParentDeviceID   string
	ParentChannelID  int64
	MediaID          string
	StreamType       int64
	StructServerHost string //结构化中心IP
	MediaServerHost  string
	MediaServerPort  string
	SSRCStr          string
	HttpPort         int64
	H264Port         int64
	App              string
	RtmpPlayUrl      string
	NatRtmpPlayUrl   string
	WsFlvPlayUrl     string
	//MscProxyKey      string //addStreamProxy接口返回的key
	PullStreamUrl string //拉流地址（三方接入）
	DeviceID      string
	DeviceCity    string
	MultiRate     map[string]string //多分辨率 key:= 分辨率 v:=url地址
}

// StreamResponse 视频流响应
type StreamResponse struct {
	Response
	PlayResponse
}

// MultiStreamRequest 结构化推流请求
type MultiStreamRequest struct {
	Tid               string
	StreamRequestList []StreamRequest
}

// StructStreamResponse 结构化推流响应
type StructStreamResponse struct {
	Tid                string
	StreamResponseList []StreamResponse
}

type StreamRequest struct {
	PlayRequest    PlayRequest
	PlayResponse   PlayResponse
	PushStreamPort PushStreamPort //分发的推流端口
}

// HttpApiMergeStreamRect 合流参数
type HttpApiMergeStreamRect struct {
	X        int32  `json:"x"`
	Y        int32  `json:"y"`
	Width    int32  `json:"width"`
	Height   int32  `json:"height"`
	App      string `json:"app"`
	Stream   string `json:"stream"`
	DeviceID string `json:"deviceid"`
}

// HttpApiStartMergeStreamRequest 视频合流请求
type HttpApiStartMergeStreamRequest struct {
	Tid          string                    `json:"tid"`
	Width        int32                     `json:"width"`
	Height       int32                     `json:"height"`
	DestApp      string                    `json:"destApp"`
	DestStreamId string                    `json:"destStreamId"`
	ChildRect    []*HttpApiMergeStreamRect `json:"childRect"`
}

// ThirdPartyCallRequest 第三方呼叫控制请求
type ThirdPartyCallRequest struct {
	DeviceID  string
	UserToken string
}

// ThirdPartyCallMsg 第三方呼叫控制消息
type ThirdPartyCallMsg struct {
	MsgType      int64 // 1 是否在线 2 推送播放地址 3 停止播放
	MsgNum       int64
	User         string
	PlayResponse *PlayResponse
}

type CleanUpRequest struct {
	Token string
}
